<?php

class Application_Model_Stany
{

    protected $_id_stan;
    protected $_nazwa;

    public function __construct(array $options = null)
    {
        if (is_array($options))
        {
            $this->setOptions($options);
        }
    }

    public function __set($name, $value)
    {
        $metoda = 'set' . ucfirst($name);

        if (('mapper' == $name) || !method_exists($this, $metoda))
        {
            throw new exception('Nie ma takiej wĹ‚aĹ›ciwoĹ›Ä‡i!');
        }

        $this->$metoda($value);
    }

    public function __get($name)
    {
        $metoda = 'get' . ucfirst($name);

        if (('mapper' == $name) || !method_exists($this, $metoda))
        {
            throw new exception('Nie ma takiej wĹ‚aĹ›ciwoĹ›Ä‡i!');
        }

        $this->$metoda();
    }

    public function setOptions(array $options)
    {
        $methods = get_class_methods($this);

        foreach ($options as $key => $value)
        {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods))
            {
                $this->$method($value);
            }
        }
        return $this;
    }

    public function setIdStan($id)
    {
        $this->_id_stan = (int) $id;
        return $this;
    }

    public function getIdStan()
    {
        return $this->_id_stan;
    }

    public function setNazwa($nazwa)
    {
        $this->_nazwa = (string) $nazwa;
        return $this;
    }

    public function getNazwa()
    {
        return $this->_nazwa;
    }

}

